package io.yuncheng.common.config;

import io.yuncheng.modules.job.entity.ScheduleJobEntity;
import io.yuncheng.modules.job.service.ScheduleJobService;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 *  项目初始化执行的数据
 * @Author shouxu
 * @Date 2021/1/29 15:03
 */
@Component
public class AdminApplicationRunner implements ApplicationRunner {
    @Resource
    private ScheduleJobService scheduleJobService;
    @Override
    public void run(ApplicationArguments args) throws Exception {
        ScheduleJobEntity scheduleJob = new ScheduleJobEntity();
        scheduleJob.setBeanName("appLogArithmeticTask");
        scheduleJob.setParams("{}");
        scheduleJob.setRemark("汇总智能体日志定时执行任务");
        scheduleJob.setCronExpression("0 0 1 * * ?");
        List<ScheduleJobEntity> list = scheduleJobService.list();
        for (ScheduleJobEntity scheduleJobEntity : list) {
            if(scheduleJobEntity.getBeanName().equals(scheduleJob.getBeanName())){
                //已经有的数据直接返回
                return;
            }
        }
        scheduleJobService.saveJob(scheduleJob);
    }
}
